Radar Host Communication library  2020.08.13
EndpointRadarDeviceStatus.c
Go to the documentation of this file.
1 
10 /* ===========================================================================
11 ** Copyright (C) 2017 - 2019 Infineon Technologies AG
12 ** All rights reserved.
13 ** ===========================================================================
14 **
15 ** ===========================================================================
16 ** This document contains proprietary information of Infineon Technologies AG.
17 ** Passing on and copying of this document, and communication of its contents
18 ** is not permitted without Infineon's prior written authorisation.
19 ** ===========================================================================
20 */
21 
22 /*
23 ==============================================================================
24  1. INCLUDE FILES
25 ==============================================================================
26 */
28 #define __PROTOCOL_INCLUDE_ENDPOINT_ONLY_API__
29 #include "Protocol_internal.h"
30 #undef __PROTOCOL_INCLUDE_ENDPOINT_ONLY_API__
31 #include <stdlib.h>
32 #include <string.h>
33 
34 /*
35 ==============================================================================
36  2. LOCAL DEFINITIONS
37 ==============================================================================
38 */
50 #define MSG_STATUS_REQ_RES 0x4A
51 #define MSG_STATUS_REQ_IND 0x4B
55 /*
56 ==============================================================================
57  5. LOCAL FUNCTION PROTOTYPES
58 ==============================================================================
59 */
60 
76 static void parse_payload(int32_t protocol_handle, uint8_t endpoint,
77  const uint8_t* payload, uint16_t payload_size);
78 
83 extern const char* ep_radar_get_error_code_description(uint16_t error_code);
84 
85 static int32_t parse_frame_info(int32_t protocol_handle, uint8_t endpoint,
86  const uint8_t* payload,
87  uint16_t payload_size);
88 
89 /*
90 ==============================================================================
91  4. DATA
92 ==============================================================================
93 */
94 
108 const Endpoint_Definition_t ep_RadarDeviceStatus_definition =
109 {
110  /*.type =*/ 0x44455653,
111  /*.min_version =*/ 1,
112  /*.max_version =*/ 1,
113  /*.description =*/ "ifxRadarDeviceStatus",
114  /*.parse_payload =*/ parse_payload,
115  /*.get_status_descr =*/ ep_radar_get_error_code_description
116 };
117 
135 static Callback_Device_Status_t callback_device_status = NULL;
136 
141 static void* context_device_status = NULL;
142 
145 /*
146 ==============================================================================
147  6. LOCAL FUNCTIONS
148 ==============================================================================
149 */
150 
151 static void parse_payload(int32_t protocol_handle, uint8_t endpoint,
152  const uint8_t* payload, uint16_t payload_size)
153 {
154  /* try to parse payload for all supported message types, stop when parsing
155  * was successful
156  */
157  if (parse_frame_info(protocol_handle, endpoint,
158  payload, payload_size))
159  {
160  return;
161  }
162 }
163 
164 static int32_t parse_frame_info(int32_t protocol_handle, uint8_t endpoint,
165  const uint8_t* payload,
166  uint16_t payload_size)
167 {
168  const uint16_t header_size = 9;
169 
170  if ((protocol_read_payload_uint8(payload, 0) == MSG_STATUS_REQ_RES) &&
171  (payload_size >= header_size))
172  {
173  if (callback_device_status)
174  {
175 
176  device_status_response_t mcu_status;
177 
178  mcu_status.error_type = protocol_read_payload_uint8(payload, 1);
179  mcu_status.error_code = protocol_read_payload_uint16(payload, 2);
180  mcu_status.frame_count = protocol_read_payload_uint32(payload, 4);
181  mcu_status.error_msg_size = protocol_read_payload_uint16(payload, 8);
182  char *msg = malloc(mcu_status.error_msg_size * sizeof(char));
183  for(uint16_t i = 0; i < mcu_status.error_msg_size; i++)
184  {
185  msg[i] = protocol_read_payload_uint8(payload, 10 + i);
186  }
187  mcu_status.message = msg;
188 
189  /* send frame info to callback */
190  callback_device_status(context_device_status, protocol_handle,
191  endpoint, &mcu_status);
192  free(msg);
193 
194 
195  return 1;
196  }
197  }
198 
199  return 0;
200 }
201 
202 
203 /*
204 ==============================================================================
205  7. EXPORTED FUNCTIONS
206 ==============================================================================
207 */
208 
209 int32_t ep_device_status_is_compatible_endpoint(int32_t protocol_handle,
210  uint8_t endpoint)
211 {
212  return protocol_is_endpoint_compatible(protocol_handle, endpoint,
214 }
215 
217 {
218  callback_device_status = callback;
219  context_device_status = context;
220 }
221 
222 int32_t ep_device_status_get_status(int32_t protocol_handle, uint8_t endpoint)
223 {
224  /* build message to send */
225  uint8_t cmd_message[1];
226 
227  protocol_write_payload_uint8(cmd_message, 0, MSG_STATUS_REQ_IND);
228 
229  /* send message and process received response */
230  return protocol_send_and_receive(protocol_handle, endpoint,
232  cmd_message, sizeof(cmd_message));
233 }
234 
235 /* --- End of File -------------------------------------------------------- */
const Endpoint_Definition_t ep_RadarDeviceStatus_definition
#define MSG_STATUS_REQ_IND
const char * ep_radar_get_error_code_description(uint16_t error_code)
void(* Callback_Device_Status_t)(void *context, int32_t protocol_handle, uint8_t endpoint, const device_status_response_t *pStatus)
#define MSG_STATUS_REQ_RES
int32_t protocol_send_and_receive(int32_t protocol_handle, uint8_t endpoint, const Endpoint_Definition_t *endpoint_definiton, const uint8_t *payload, uint16_t payload_size)
Definition: Protocol.c:957
void ep_device_status_set_callback_mcu_status(Callback_Device_Status_t callback, void *context)
This functions registers a callback device status.
int32_t protocol_is_endpoint_compatible(int32_t protocol_handle, uint8_t endpoint, const Endpoint_Definition_t *endpoint_definiton)
Definition: Protocol.c:927
int32_t ep_device_status_get_status(int32_t protocol_handle, uint8_t endpoint)
int32_t ep_device_status_is_compatible_endpoint(int32_t protocol_handle, uint8_t endpoint)
This function checks if an endpoint in a device is a MCU Status endpoint.